package com.bj58.mis.apm.server.statistics.controller;

import com.bj58.mis.apm.server.core.common.result.Page;
import com.bj58.mis.apm.server.core.common.result.ResultBean;
import com.bj58.mis.apm.server.statistics.dto.job.KylinJob;
import com.bj58.mis.apm.server.statistics.dto.job.KylinJobInfo;
import com.bj58.mis.apm.server.statistics.dto.job.KylinJobStepInfo;
import com.bj58.mis.apm.server.statistics.query.PageInfo;
import com.bj58.mis.apm.server.statistics.query.job.JobQuery;
import com.bj58.mis.apm.server.statistics.service.JobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * 〈一句话功能简述〉<br> 
 * 〈任务概况〉
 *
 * @author zhangyu84
 * @create 2018/6/19
 * @since 1.0.0
 */
@RestController
@RequestMapping("/job")
@Api(tags = "Job相关API", description = "/job")
public class JobController extends BaseController<JobService>{
    @ApiOperation(value = "Job任务概况", notes = "查询当前用户有权限的Job")
    @GetMapping(path="/jobSurvey")
    public ResultBean<KylinJob> jobSurvey(@ModelAttribute JobQuery jobQuery){
        String currUser=getLoginUserName();
        return ResultBean.success(this.service.jobSurvey(currUser,jobQuery));
    }

    @ApiOperation(value = "Job任务列表", notes = "查询当前用户有权限的Job任务列表")
    @GetMapping(path="/jobList")
    public ResultBean<Page<KylinJobInfo>> jobList(@ModelAttribute JobQuery jobQuery,
                                                  @ModelAttribute PageInfo pageInfo){
        String currUser=getLoginUserName();
        return ResultBean.success(this.service.jobList(currUser,jobQuery,pageInfo));
    }

    @ApiOperation(value = "Job任务详情", notes = "通过Id查询一个任务的具体信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id", value = "任务的ID", paramType = "path", required = true, dataType = "String")
                    })
            @GetMapping(path="/{id}")
            public ResultBean<KylinJobStepInfo> getJobInfoById( @PathVariable(name="id", required = false) String id){
        return ResultBean.success(this.service.getJobInfoById(id));
    }

}
